import { Component, OnInit,Output,Input,EventEmitter } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-screening',
  templateUrl: './screening.component.html',
  styleUrls: ['./screening.component.scss']
})
export class ScreeningComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService,public request:RequestService) {
    
  }

  @Output()  private  outer=new EventEmitter();
  @Input() puc_msg:any; 
  
  field1 = []             //table表格1-主表列字段集合
  data1_parmKey = 'SWITCH_DOMAIN'   //table表格1-主表动态列代码标识
  indexTableId = 'popup01_tblist_screen';

  ngOnInit() {
  }

  unitStatus_list=JSON.parse(localStorage.getItem("unitStatus_list"))
  popup01_url='';
  popup01_par='';
  popup01_data={}
  popup01 = false;
  popup01_show(par,url?): void {//组织筛选弹窗，第二参数不传为默认使用接口/user/scope/list，否则使用第二参数接口
    if(!this.utilService.patrn.test(url)||url==null||typeof(url) == "undefined"){
      this.popup01_url='/erp/user/scope/list'
    }else{
      this.popup01_url=url
    }
    this.popup01_par=par;
	  this.interfaceService.dynamicFieldSelect(this, 1, 'popup01_table', {});
  }

  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url='';
    this.popup01_par='';
    this.searchData.popup01_ss1='';
    this.searchData.popup01_ss2='';
  }

  searchData = {
    popup01_ss1: '',
    popup01_ss2: ''
  }
  popup01_table(){
    this.popup01_data={}
    Object.assign(this.popup01_data, this.popup01_par,{unitCode:this.searchData.popup01_ss1,unitName:this.searchData.popup01_ss2});
    this.interfaceService.postPage(this.popup01_url,this.popup01_data).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if(data.code==200){
        this.popup01 = true;
        this.popup01_listTable(data.object.list);
      }else{
        layer.msg(data.message)
      }
    }
    });
  }

  popup01_listTable(da):void{
    setTimeout(()=>{ 
      layui.use(['table'], (obj)=>{
        var  table = layui.table
        var tab = this.utilService.postTable(da, "#" + this.indexTableId, this.field1)
        tab["title"] = '切换组织数据表'
        tab["done"] = (res) => {
          this.utilService.tdTitle()
        }
        table.render(tab);
        //监听行单击事件row   监听行双击事件rowDouble
        table.on('row(' + this.indexTableId + ')', (obj)=>{
          obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');//标注选中样式
         });
        table.on('rowDouble(' + this.indexTableId + ')', (obj)=>{
          this.popup01_hide();
          this.outer.emit(obj.data)      
         });
      });
    },50);
  }

}
